(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

type +'a io

type io_r = [ | `IO_Read ]
type io_w = [ | `IO_Write ]
type io_s = [ | `IO_Seek ]
type io_rs = [ | io_r | io_s ]
type io_ws = [ | io_w | io_s ]
type io_rw = [ | io_r | io_w ]
type io_rws = [ | io_r | io_w | io_s ]
type istream = io_r io
type irstream = io_rs io
type ostream = io_w io
type orstream = io_ws io
type iostream = io_rw io
type iorstream = io_rws io

val io_make :
  (unit -> unit) ->
    (unit -> char) ->
      (int -> string) ->
        (unit -> bool) ->
          (char -> unit) ->
            (string -> unit) ->
              (unit -> int) ->
                (unit -> int) -> (unit -> int) -> (int -> unit) -> iorstream
  
val io_make_read :
  (unit -> unit) ->
    (unit -> char) -> (int -> string) -> (unit -> bool) -> istream
  
val io_make_write :
  (unit -> unit) ->
    (char -> unit) -> (string -> unit) -> (unit -> int) -> ostream
  
val io_make_read_seek :
  (unit -> unit) ->
    (unit -> char) ->
      (int -> string) ->
        (unit -> bool) ->
          (unit -> int) -> (unit -> int) -> (int -> unit) -> irstream
  
val io_make_write_seek :
  (unit -> unit) ->
    (char -> unit) ->
      (string -> unit) ->
        (unit -> int) ->
          (unit -> int) -> (unit -> int) -> (int -> unit) -> orstream
  
val io_make_read_write :
  (unit -> unit) ->
    (unit -> char) ->
      (int -> string) ->
        (unit -> bool) ->
          (char -> unit) -> (string -> unit) -> (unit -> int) -> iostream
  
val io_free : 'a io -> unit
val io_read_char : [> | io_r] io -> char
val io_read_string : [> | io_r] io -> int -> string
val io_eof : [> | io_r] io -> bool
val io_write_char : [> | io_w] io -> char -> unit
val io_write_string : [> | io_w] io -> string -> unit
val io_bytes_written : [> | io_w] io -> int
val io_size : [> | io_s] io -> int
val io_pos : [> | io_s] io -> int
val io_seek : [> | io_s] io -> int -> unit
val io_coerce_i : [> | io_r] io -> istream
val io_coerce_o : [> | io_w] io -> ostream
val io_coerce_ir : [> | io_rs] io -> irstream
val io_coerce_or : [> | io_ws] io -> orstream
val io_coerce_io : [> | io_rw] io -> iostream
val io_coerce_ior : [> | io_rws] io -> iorstream
